Removed the need to use Self::Api #1252
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Abstract
In the current state of the sdk, the user has the choice to either add Self::Api for every operation he does, or relying on the macros doing it on his behalf. While the first choice is clearly inconvenient, the second one is also a big deal because the Self::Api is appended in a procedural macro (
multiversx_sc::contract
,multiversx_sc::module
ormultiversx_sc::proxy
) and have the following major drawbacks:What is this pull request about?
This pull request is not intended to be merge as is, the code is not clean and some tests don't pass. It is a draft to see what could be a potential solution to the above problematic.
I made a LOT of changes to make the VMApi parameter instantiated at compile time. The first notable change is the renaming of the known managed type and mappers to append the prefix "Base". I only did it for BigUint and SingleValueMapper which become BaseBigUint and BaseSingleValueMapper.
The next change was to modify the
multiversx_sc::imports!
macro, I added two things:type BigUint = BaseBigUint<CurrentApi>
ortype SingleValueMapper<T> = BaseSingleValueMapper<CurrentApi, T>
. This is done in the declarative macro instead of a procedural one, so the developer can immediately access to the IDEs features (autocompletions, error handling, etc...)Advantages
Drawbacks
What's not working
Since the goal is not to necessarily merge this pull request, I only made the core functionalities to work, here are what's not working currently: